import BuffUtil from '@/BuffUtil';
import RandomUtil from '@/RandomUtil';
import UnitCommon from 'code/Core/Common/UnitCommon';
import TalentBase from 'code/Scripts/Abilities/base/TalentBase';
const desc = `当你受到攻击时有${ColorSafe}50%|r的几率对其造成${ColorSafe}体质x20%|r的反伤|n觉醒后在触发反击时获得生命回复与冷却加速`;
const art = 'ReplaceableTextures\\CommandButtons\\BTNThorns.blp';
const name = '反击';
const config: TalentConfigModel = {
    id: 'talent_TalentReflectHit',
    name,
    desc,
    art,
    buffType: {
        id: 'buff_t_reflecthit',
        art,
        name,
        ubertip: desc,
    },
    buffTypePlus: {
        id: 'buff_t_reflecthit_plus',
        art,
        name: '反击[觉醒]',
        ubertip: `当你受到攻击时有${ColorSafe}50%|r的几率对其造成${ColorSafe}体质x20%|r的反伤,并获得${ColorSafe}1%|r的生命回复与冷却加速`,
    },
};
export default class TalentReflectHit extends TalentBase {
    static instance: TalentReflectHit;
    buffTypePlusEffect: AppBuffType = {
        id: 'buff_t_reflecthit_plus_effect',
        art,
        name: '反击增效',
        ubertip: '获得生命回复增强与冷却加速',
        attribute: {
            生命恢复增强: 0.01,
            冷却_反击觉醒: 0.01,
        },
        dur: 10,
        stackCountMax: -1,
        stackDurMode: true,
    };
    constructor(p?: TalentConfigModel) {
        super(p);
        TalentReflectHit.instance = this;
        this.setTalentConfig(config);
        EventManager.onTakeAttack(this.attackEffect.bind(this));
        BuffUtil.registerBuffType(this.buffTypePlusEffect);
    }
    attackEffect(d: DamageEventData) {
        let { unEffect, plus } = TalentReflectHit.instance.talentUnEffect(d.target);
        if (unEffect) return;
        let r = RandomUtil.randomPercent();
        if (r > 0.5) {
            return;
        }
        let dmg = UnitCommon.取总耐力(d.target) * 0.2;
        if (plus) {
            let buff = BuffUtil.addBuff(d.target, this.buffTypePlusEffect.id, d.target);
            if (UnitCommon.是否精英单位(d.source)) {
                buff.stackCount += 4;
            }
        }
        DamageSystemInstance.applyReflectDamage(d.source, d.target, dmg);
    }
}
